﻿'/*
' * FAHWatch7 Copyright Marvin Westmaas ( mtm )
' *
' * This program is free software; you can redistribute it and/or
' * modify it under the terms of the GNU General Public License
' * as published by the Free Software Foundation; version 2
' * of the License. See the included file GPLv2.TXT.
' * 
' * This program is distributed in the hope that it will be useful,
' * but WITHOUT ANY WARRANTY; without even the implied warranty of
' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' * GNU General Public License for more details.
' * 
' * You should have received a copy of the GNU General Public License
' * along with this program; if not, write to the Free Software
' * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
' */
'/*
Imports System.Windows.Forms
Public Class dgFilters
    Private bManual As Boolean = False
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub chkDateSelection_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDateSelection.CheckedChanged
        Try
            If bManual Then Exit Sub
            gbDateSelection.Enabled = chkDateSelection.Checked
            'Check if an rb is checked, if not check the first one
            Dim cButton As RadioButton = Nothing
            For Each rbCtrl As Control In gbDateSelection.Controls
                If TypeOf (rbCtrl) Is RadioButton Then
                    If CType(rbCtrl, RadioButton).Checked Then
                        cButton = CType(rbCtrl, RadioButton)
                        Exit For
                    End If
                End If
            Next
            If IsNothing(cButton) Then
                For Each rbCtrl As Control In gbDateSelection.Controls
                    If TypeOf (rbCtrl) Is RadioButton Then
                        CType(rbCtrl, RadioButton).Checked = True
                        Exit For
                    End If
                Next
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub


    Private Sub dgFilters_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            cmbClients.Text = cmbClients.Items(0).ToString
            cmbSlots.Text = cmbSlots.Items(0).ToString
            cmbHardware.Text = cmbHardware.Items(0).ToString
            cmbCoreStatus.Text = cmbCoreStatus.Items(0).ToString
            cmbServerResponce.Text = cmbServerResponce.Items(0).ToString
            cmbGroupRoot.Text = cmbGroupRoot.Items(0).ToString
            cmbFahCore.Text = cmbFahCore.Items(0).ToString
            cmbSort.Text = cmbSort.Items(0).ToString
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub chkGrouping_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkGrouping.CheckedChanged
        Try
            If bManual Then Exit Sub
            cmbGroupRoot.Enabled = chkGrouping.Checked
            cmdAddGroupingNode.Enabled = chkGrouping.Checked
            cmdRemoveGroupingNode.Enabled = chkGrouping.Checked
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub


    Private Sub tcFilter_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tcFilter.SelectedIndexChanged
        Try
            If tcFilter.SelectedIndex = 0 Then
                cmdNext.Enabled = True
                cmdPrev.Enabled = False
            ElseIf tcFilter.SelectedIndex = 2 Then
                cmdNext.Enabled = False
                cmdPrev.Enabled = True
            Else
                cmdNext.Enabled = True
                cmdPrev.Enabled = True
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
        Try
            tcFilter.SelectedIndex = tcFilter.SelectedIndex + 1
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmdPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrev.Click
        Try
            tcFilter.SelectedIndex = tcFilter.SelectedIndex - 1
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmbClients_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbClients.SelectedIndexChanged
        Try
            cmdAddClient.Enabled = Not (cmbClients.SelectedIndex = 0)
            cmdRemoveClient.Enabled = Not (cmbClients.SelectedIndex = 0)
            If cmbClients.SelectedIndex = 0 Then
                'Fill listbox with client names!
                lbClients.Items.Clear()
                cmbClientNames.Visible = False
                For Each Client In LogParser.Clients
                    lbClients.Items.Add(Client.ClientName)
                Next
            Else
                'Clean listbox
                lbClients.Items.Clear()
                'Fill cmbclientnames
                cmbClientNames.Items.Clear()
                For Each Client In LogParser.Clients
                    cmbClientNames.Items.Add(Client.ClientName)
                Next
                cmbClientNames.Visible = True
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmbFahCore_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbFahCore.SelectedIndexChanged
        Try
            cmdAddFahCore.Enabled = Not (cmbFahCore.SelectedIndex = 0)
            cmdRemoveFahCore.Enabled = Not (cmbFahCore.SelectedIndex = 0)
            If cmbFahCore.SelectedIndex = 0 Then
                'Fill listbox with client names!
                lbFahCore.Items.Clear()
                cmbFahCoreNames.Visible = False
                For Each Client In LogParser.Clients
                    lbFahCore.Items.Add(Client.ClientName)
                Next
            Else
                'Clean listbox
                lbFahCore.Items.Clear()
                'Fill cmbclientnames
                cmbFahCoreNames.Items.Clear()
                For Each Client In LogParser.Clients
                    cmbFahCoreNames.Items.Add(Client.ClientName)
                Next
                cmbFahCoreNames.Visible = True
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmbSlots_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSlots.SelectedIndexChanged
        Try
            cmdAddSlot.Enabled = Not (cmbSlots.SelectedIndex = 0)
            cmdRemoveSlot.Enabled = Not (cmbSlots.SelectedIndex = 0)
            If cmbSlots.SelectedIndex = 0 Then
                'Fill listbox with client names!
                lbSlots.Items.Clear()
                cmbSlotNames.Visible = False
                For Each Client In LogParser.Clients
                    lbSlots.Items.Add(Client.ClientName)
                Next
            Else
                'Clean listbox
                lbSlots.Items.Clear()
                'Fill cmbclientnames
                cmbSlotNames.Items.Clear()
                For Each Client In LogParser.Clients
                    cmbSlotNames.Items.Add(Client.ClientName)
                Next
                cmbSlotNames.Visible = True
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmbHardware_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbHardware.SelectedIndexChanged
        Try
            cmdAddHW.Enabled = Not (cmbHardware.SelectedIndex = 0)
            cmdRemoveHW.Enabled = Not (cmbHardware.SelectedIndex = 0)
            If cmbHardware.SelectedIndex = 0 Then
                'Fill listbox with client names!
                lbHW.Items.Clear()
                cmbHardwareNames.Visible = False
                For Each Client In LogParser.Clients
                    lbHW.Items.Add(Client.ClientName)
                Next
            Else
                'Clean listbox
                lbHW.Items.Clear()
                'Fill cmbclientnames
                cmbHardwareNames.Items.Clear()
                For Each Client In LogParser.Clients
                    cmbHardwareNames.Items.Add(Client.ClientName)
                Next
                cmbHardwareNames.Visible = True
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmbCoreStatus_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCoreStatus.SelectedIndexChanged
        Try
            cmdAddCoreStatus.Enabled = Not (cmbCoreStatus.SelectedIndex = 0)
            cmdRemoveCoreStatus.Enabled = Not (cmbCoreStatus.SelectedIndex = 0)
            If cmbCoreStatus.SelectedIndex = 0 Then
                'Fill listbox with client names!
                lbCoreStatus.Items.Clear()
                cmbCoreStatusNames.Visible = False
                For Each Client In LogParser.Clients
                    lbCoreStatus.Items.Add(Client.ClientName)
                Next
            Else
                'Clean listbox
                lbCoreStatus.Items.Clear()
                'Fill cmbclientnames
                cmbCoreStatusNames.Items.Clear()
                For Each Client In LogParser.Clients
                    cmbCoreStatusNames.Items.Add(Client.ClientName)
                Next
                cmbCoreStatusNames.Visible = True
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmbServerResponce_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbServerResponce.SelectedIndexChanged
        Try
            cmdAddServerResponse.Enabled = Not (cmbServerResponce.SelectedIndex = 0)
            cmdRemoveServerResponce.Enabled = Not (cmbServerResponce.SelectedIndex = 0)
            If cmbServerResponce.SelectedIndex = 0 Then
                'Fill listbox with client names!
                lbServerResponce.Items.Clear()
                cmbServerResponceNames.Visible = False
                For Each Client In LogParser.Clients
                    lbServerResponce.Items.Add(Client.ClientName)
                Next
            Else
                'Clean listbox
                lbServerResponce.Items.Clear()
                'Fill cmbclientnames
                cmbServerResponceNames.Items.Clear()
                For Each Client In LogParser.Clients
                    cmbServerResponceNames.Items.Add(Client.ClientName)
                Next
                cmbServerResponceNames.Visible = True
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub lbFilters_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbFilters.SelectedIndexChanged
        Try
            If lbFilters.SelectedIndex = -1 Or bManual Then Exit Sub
            If lbFilters.SelectedIndex = 0 Then
                'Default view ( uneditable, base for all new filters )
                UI_from_filter("Default")
            Else
                'Ui_from_filter(lbfilters.items(lbfilters.selectedindex))
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub
    Private Sub UI_from_filter(ByVal Filtername As String)
        Try
            txtFilterName.Text = Filtername
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmdAddGroupingNode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddGroupingNode.Click

    End Sub
End Class
